#include "fig_pickup_manager.h"
#include "fig_pickup_collection.h"
#include "fig_pickup_animation.h"



FIGPickupManager&		FIGPickupManager::Instance()
{
	static FIGPickupManager	Inst;
	return Inst;
}


void	FIGPickupManager::Render(const math::Vec2& Offset,float Scale)
{
	 for(unsigned int i = 0; i < m_PickupCollections.size(); i++)
	{
		FIGPickupCollection* pCol = m_PickupCollections[i];
		pCol->Render(Offset,Scale);
	}

	FIGPickupAnimation::Instance().Render(Offset,Scale);
}

void	FIGPickupManager::RenderDebug(const math::Vec2& Offset,float Scale)
{
	 for(unsigned int i = 0; i < m_PickupCollections.size(); i++)
	{
		FIGPickupCollection* pCol = m_PickupCollections[i];
		pCol->RenderDebug(Offset,Scale);
	}
	FIGPickupAnimation::Instance().RenderDebug(Offset,Scale);
}

void	FIGPickupManager::RenderShadow(const math::Vec2& Offset,float Scale)
{
	 for(unsigned int i = 0; i < m_PickupCollections.size(); i++)
	{
		FIGPickupCollection* pCol = m_PickupCollections[i];
		pCol->RenderShadow(Offset,Scale);
	}
}

void	FIGPickupManager::Tick(float dt)
{
    for(unsigned int i = 0; i < m_PickupCollections.size(); i++)
	{
		FIGPickupCollection* pCol = m_PickupCollections[i];
		pCol->Tick(dt);
	}

	FIGPickupAnimation::Instance().Tick(dt);
}


void	FIGPickupManager::Clear()
{
    for(unsigned int i = 0; i < m_PickupCollections.size(); i++)
	{
		FIGPickupCollection* pCol = m_PickupCollections[i];
		pCol->Clear();
		UTIL_SAFE_DELETE(pCol);
	}
	m_PickupCollections.resize(0);
}

void	FIGPickupManager::Spawn(const std::string& TypeName,
								const math::Vec2& Pos
											)
{
	FIGPickup::PICKUP_TYPES Type = FIGPickup::MapNameToType(TypeName);
	Spawn(Type,Pos);
}

void	FIGPickupManager::Spawn(FIGPickup::PICKUP_TYPES Type, 
											const math::Vec2& Pos
										)
{
	bool Found = false;
	for( int i = (int)m_PickupCollections.size() - 1; i >= 0; i--)
	{
		FIGPickupCollection* pCol = m_PickupCollections[i];
		if ( pCol->GetType() == Type)
		{
			pCol->Spawn(Type , Pos);
			Found = true;
			i = -1;
		}		
	}

	if(!Found)
	{
		FIGPickupCollection* pCol = new FIGPickupCollection(Type);
		m_PickupCollections.push_back(pCol);
		pCol->Spawn(Type , Pos);
	}
}


